package com.aaa.sso.controller;

import com.aaa.common.bo.Member;
import com.aaa.common.util.Result;
import com.aaa.sso.service.AuthService;
import com.aaa.sso.util.CustomUsernamePasswordToken;
import com.aaa.sso.util.LoginType;
import com.netflix.discovery.converters.Auto;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * @author Xiujie Yu
 * @Date 2021-01-21
 * @Time 14:37
 */
@RestController
@RequestMapping("memberLogin")
public class MemberLoginController {
    @Resource
    private RedisTemplate<String,Object> redisTemplate;

    @Resource(name = "authMemberService")
    private AuthService authService;
    /**
     * 功能描述:用户或会员登陆认证
     * @param userName String
     * @param password String
     * @return com.aaa.common.util.Result
     */
    @GetMapping("auth")
    public Result<Map<String, Object>> authMember(String userName, String password){
        return this.authService.authUserMember(userName,password);
    }

    /**
     * 功能描述:验证Token方法
     * @param token String
     * @return boolean
     */
    @GetMapping("checkToken")
    public boolean checkToken(@RequestHeader("token") String token){
        return this.authService.checkToken(token);
    }

    /**
     * 从redis获得当前登录人主体信息
     */
    @GetMapping("subject")
    public Object getSubjectInformation(HttpServletRequest request){
        String token = request.getHeader("Authorization");
        return redisTemplate.opsForValue().get(token);
    }
}
